package com.etc.controller;

import com.etc.entity.Engage;
import com.etc.service.EngageService;
import com.etc.util.Layui;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/EngageController")
public class EngageController {
   @Autowired
   EngageService service;

    /**
     * 添加订单
     * @param engage
     * @return
     */
    @RequestMapping("/addEngage")
    @ResponseBody
    public boolean addEngage(@RequestParam(value = "engage") Engage engage) {
       //调用业务层
        boolean en = service.addEngage(engage);
        return en;
    }

    /**
     * 根据房间类型编号删除订单
     * @param rtid
     * @return
     */
    @RequestMapping("/delEngage")
    @ResponseBody
    public boolean delEngage(@RequestParam(value = "rtid")String rtid){
        //调用业务层
        boolean en = service.delEngage(rtid);
        return  en;
    }

    /**
     * 根据房间类型编号修改订单
     * @param engage
     * @return
     */
    @RequestMapping("/updateEngage")
    @ResponseBody
    public int  modifyEngage(@RequestParam(value = "engage")Engage engage){
        //调用业务层
        int en = service.modifyEngage(engage);
        return en;
    }

    /**
     * 查询所有订单
     * @param pageNum
     * @param pageSize
     * @param roomNum
     * @param engageStatus
     * @return
     */
    @RequestMapping("/getqueryAllEngage")
    @ResponseBody
    public Layui getqueryAllEngage(@RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                                   @RequestParam(value = "pageSize",defaultValue = "3")int pageSize,
                                   @RequestParam(value = "roomNum",defaultValue = "0")int roomNum,
                                   @RequestParam(value = "engageStatus",defaultValue = "88")int engageStatus){
        PageInfo<Engage> pageInfo = (PageInfo<Engage>) service.getAllEngage(pageNum,pageSize,roomNum,engageStatus);
        return Layui.data(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 根据用户编号查询订单
     * @param userId
     * @return
     */
    @RequestMapping("/getEngage")
    @ResponseBody
    public List<Engage> getEngage(String userId){
        List<Engage> list = service.queryEngageByUserId(userId);
        return list;
    }

    /**
     * 修改订单
     * @param userId
     */
    @RequestMapping("/updateUserEngage")
    @ResponseBody
    public void updateUserEngage(String userId){
        service.updateUserEngage(userId);
    }

    /**
     * 添加订单
     * @param userId
     * @param rtId
     * @param roomNum
     * @param begin
     * @param end
     * @return
     */
    @RequestMapping("/userAddEngage")
    @ResponseBody
    public boolean userAddEngage(String userId,String rtId,Integer roomNum,String begin,String end){
        boolean n = service.userAddEngage(userId, rtId, roomNum, begin, end);
        return n;
    }
}
